#pragma once

#include <string>
#include "../util.hpp"

namespace pharmacy_server
{
    struct User
    {
        using tuple_of_user = std::tuple<std::string, std::string, std::string>;

        User() = default;

        User(const std::string& username, const std::string& password, const std::string& role)
            : username(username)
            , password(password)
            , role(role)
        {
        }

        std::string username;
        std::string password;
        std::string role;

        Json::Value to_json() const
        {
            Json::Value root;
            root["username"] = username;
            root["password"] = password;
            root["role"] = role;
            return root;
        }

        void from_json(const Json::Value& root)
        {
            username = root["username"].asString();
            password = root["password"].asString();
            role = root["role"].asString();
        }

        tuple_of_user to_tuple() const
        {
            return std::make_tuple(username, password, role);
        }

        void from_tuple(const tuple_of_user& tuple)
        {
            username = std::get<0>(tuple);
            password = std::get<1>(tuple);
            role = std::get<2>(tuple);
        }

        static User from_tuple_quickly(const tuple_of_user& tuple)
        {
            std::string username = std::get<0>(tuple);
            std::string password = std::get<1>(tuple);
            std::string role = std::get<2>(tuple);
            return User(username, password, role);
        }
    };
}